package com.hzw.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzw.api.IUserService;

import com.hzw.common.PageResult;
import com.hzw.dao.UserDao;
import com.hzw.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserService implements IUserService {

    @Autowired
    UserDao userDao;

    @Override
    public PageResult<User> pageSelect(User user) {
        PageInfo<User> pageInfo = PageHelper.startPage(user.getPageNum(), user.getPageSize())
                .doSelectPageInfo(() ->{
                    userDao.select(user);
                });
        PageResult pageResult = new PageResult().setTotal(pageInfo.getTotal()).setResult(pageInfo.getList());
        return pageResult;
    }

    @Override
    public User selectById(User user) {
        return userDao.selectById(user.getId());
    }

    @Override
    public List<User> select(User user) {
        return userDao.select(user);
    }

    @Override
    public void updateById(User user) {
        userDao.updateById(user);
    }

    @Override
    public void delById(User user) {
        userDao.delById(user.getId());
    }

}
